<?php
require_once dirname ( __FILE__ ) . "/../Constants.php";
require_once dirname ( __FILE__ ) . '/Includes/viewer_functions.php';

if (isset ( $_GET ['model'] )) {
	require_once "../Model/" . $_GET ['model'] . ".php";
	$model = $_GET ['model'];
} else {
	die ( "model must be provided" );
}

if (isset ( $_GET ['primary_key_value'] )) {
	$primary_key_value = $_GET ['primary_key_value'];
	//get Model
	$class_vars = get_class_vars ( $model );
	$primary_key_field = $class_vars ['primary_key_field'];
	$constructor = "constructFrom_$primary_key_field";
	$class_instance = new $model ( );
	
	//construct the class
	$target = $class_instance->$constructor ( $primary_key_value );
} else {
	die ( "must provide primary_key_value" );
}

//grab all the properties
$model_properties = get_object_vars ( $target );
//var_dump ( $model_properties );

?>
<h2><?php
echo $model?></h2>
<div id="tabs">

<ul>
	<li><a href="#tabs-1">Properties</a></li>
	<?php
	$foreign_key_arrays = getForeignKeyArray ( $model_properties );
	foreach ( $foreign_key_arrays as $foreign_key_array_name ) {
		?>
		<li><a
		href="<?php echo MADAL_DIRECTORY; ?>/View/foreign_key_objects.php?primary_key_value=<?php
		echo $primary_key_value;
		?>&foreign_key_field=<?php
		echo $foreign_key_array_name?>&model=<?php echo $model ?>"><?php
		echo $foreign_key_array_name?></a></li>
	<li>
	<?php
	}
	?>
</ul>
<div id="tabs-1">
<table><?php
//TODO: add custom tags for ignoring properties for individual items
renderPropertiesInputsTitles($target, $model_properties, $ignore_properties );
renderPropertiesInputsRows ($target, $model_properties, $ignore_properties );
?>
</table>
</div>
</div>